package com.the_ring.chapter16;

import android.content.Context;
import android.hardware.Sensor;
import android.hardware.SensorManager;
import android.os.Bundle;

import androidx.activity.EdgeToEdge;
import androidx.appcompat.app.AppCompatActivity;
import androidx.core.graphics.Insets;
import androidx.core.view.ViewCompat;
import androidx.core.view.WindowInsetsCompat;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class MainActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
    }

    Map<Integer, String> sensorMap = new HashMap<>();
    String[] sensorType = new String[]{"加速度", "磁场", "方向", "陀螺仪", "光线", "压力", "温度", "距离", "重力", "线性加速度", "旋转矢量", "相对湿度", "环境温度", "无标定磁场", "无标定旋转矢量", "未校准陀螺仪", "特殊动作", "步行检测", "步行计数", "地磁旋转矢量", "心跳速率", "倾斜检测", "唤醒手势", "掠过手势"};
    // 显示手机自带的传感器信息
    private void showSensorInfo() {

        // 从系统服务中获取传感器管理类
        SensorManager sensorManager = (SensorManager) getSystemService(Context.SENSOR_SERVICE);
        // 获取当前设备支持idea传感器列表
        List<Sensor> sensorList = sensorManager.getSensorList(Sensor.TYPE_ALL);
        String showContent = "当前支持的传感器包括：\n";
        for (Sensor sensor : sensorList) {
//            if (sensor.getType() >= sensorType.length) {
//                continue;
//            }
            sensorMap.put(sensor.getType(), sensor.getName());
        }
        for (Map.Entry<Integer, String> entry : sensorMap.entrySet()) {
            int type = entry.getKey();
            String name = entry.getValue();
            String content = String.format("%d %s: %s \n", type, sensorType[type - 1], name);
            showContent += content;
        }
    }
}